package DD2;

class Window4 extends Thread {
    private static int money = 110;
    public void run() {
        while (true) {
            show();
        }

    }
    private static synchronized void show(){
		/*
		 * For this program, because it is extends from Thread Class. we need to state
		 * that this method is a static method
		 */
        //private synchronized void show(){ 
        if (money >=20) {

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            money-=20;
            System.out.println(Thread.currentThread().getName() + " take money,money left " + money);
        }
    }
}


public class WindowTest4 {
    public static void main(String[] args) {
        Window4 t1 = new Window4();
        Window4 t2 = new Window4();
        Window4 t3 = new Window4();


        t1.setName("Person1");
		t2.setName("Person2");
		t3.setName("Person3");

        t1.start();
        t2.start();
        t3.start();

    }
}